home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Arashi 1.1 / Game Source / jam src / STLevelSelect.c copy < prev    next >
Text File  |  1993-01-28  |  7KB  |  318 lines

  1. /*/
  2.      Project Arashi: STLevelSelect.c copy
  3.      Major release: Version 1.1, 7/22/92
  4.  
  5.      Last modification: Thursday, January 28, 1993, 12:31
  6.      Created: Wednesday, March 6, 1991, 12:00
  7.  
  8.      Copyright © 1991-1993, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "STORM.h"
  13. #include "GamePause.h"
  14. #include <math.h>
  15. #include "PlayOptions.h"
  16.  
  17.  
  18. #define    MAXSELECTABLES    96
  19.  
  20. extern    EventRecord    Event;
  21. static    Point        BoxSize;
  22.  
  23. int        FirstLevel=0;
  24. int        LastLevel=300;
  25. int        LastSelect=200;
  26.  
  27. void    DrawLevelPresentation(offset,resnum)
  28. int        offset,resnum;
  29. {
  30.                 shape    **spacehand;
  31.     register    shape    *space;
  32.     register    long    x,y;
  33.                 long    xmin,xmax;
  34.                 long    ymin,ymax;
  35.     register    int        i,angle;
  36.     register    int        *angles;
  37.                 Point    base;
  38.  
  39.  
  40.     spacehand=(void *)GetResource('SPCE',resnum);
  41.     HLock(spacehand);
  42.     space=*spacehand;
  43.     
  44.     x=0;        y=0;
  45.     xmin=0;        ymin=0;
  46.     xmax=0;        ymax=0;
  47.  
  48.     angle=0;
  49.     angles=space->ang;
  50.     for(i=0;i<space->numsegs;i++)
  51.     {    angle+= *angles++;
  52.         while(angle<0)             angle += ANGLES;
  53.         while(angle>=ANGLES)    angle -= ANGLES;
  54.         
  55.         x += Cosins[angle];        y -= Sins[angle];
  56.         if(x>xmax) xmax=x;        if(y>ymax) ymax=y;
  57.         if(x<xmin) xmin=x;        if(y<ymin) ymin=y;
  58.     }
  59.     xmax += 512;    ymax+= 512;
  60.     xmin -= 512;    ymin-= 512;
  61.     
  62.     x = -(xmin+xmax)/2;
  63.     y = -(ymin+ymax)/2;
  64.     
  65.     xmax -= xmin;
  66.     ymax -= ymin;
  67.     
  68.     if(xmax<ymax)    xmax=ymax;
  69.     
  70.     base.h = BoxSize.h/2 + offset;
  71.     base.v = VA.frame.bottom - BoxSize.v;
  72.     
  73.     VAMoveTo( x * BoxSize.h / xmax + base.h , y * BoxSize.v / xmax + base.v);
  74.     angle=0;
  75.     angles=space->ang;
  76.     for(i=0;i<space->numsegs;i++)
  77.     {    angle+= *angles++;
  78.         while(angle<0)             angle += ANGLES;
  79.         while(angle>=ANGLES)    angle -= ANGLES;
  80.         x += Cosins[angle];        y -= Sins[angle];
  81.         VASafeLineTo( x * BoxSize.h / xmax + base.h , y * BoxSize.v / xmax + base.v);
  82.     }
  83.     
  84.     HUnlock(spacehand);
  85.     ReleaseResource(spacehand);
  86. }
  87.  
  88. typedef    struct
  89. {    
  90.     int            levelresource;
  91.     ColorSpec    levelcolor;
  92.     int            levelnumber;
  93.     int            leveltemplate;
  94.     long        levelbonus;                /* added field (mz) */
  95. }    selectable;
  96.  
  97. int        CreateStable(stable,highestLastLevel)
  98. selectable    *stable;
  99. int    highestLastLevel;
  100. {
  101.     register    int            thislev=128;
  102.     register    int            levcount=0;
  103.     register    int            colorresource;
  104.     register    ColorSpec    **LCTable;
  105.     register    LevelInfo    **LInfo;
  106.     
  107.     do
  108.     {    /*
  109.         if(condition)
  110.             loadsavedgame
  111.         thislev = **GameSaveHand.lvnum;
  112.         */
  113.         
  114.         LInfo=(void *)GetResource('LEVL',thislev);
  115.         if(LInfo==0)                                return levcount;
  116.         
  117.         colorresource = (*LInfo)->lvColor;
  118.         if (colorresource == 5)                /* if invis field color use grey shade     */
  119.             colorresource = (*LInfo)->lvColor + 128;    /* for invisi levels (mz)     */
  120.             
  121.         LCTable = (void *)GetResource('CLOT',colorresource);
  122.         stable[levcount].levelresource = (*LInfo)->lvField;
  123.         stable[levcount].levelnumber = (*LInfo)->lvNumber;
  124.         stable[levcount].levelcolor = (*LCTable)[8];
  125.         stable[levcount].leveltemplate=thislev;
  126.         stable[levcount].levelbonus = (*LInfo)->lvStBonus;     /* starting bonus (mz)     */
  127.         thislev=(*LInfo)->lvNext + 1;                    /* choose odd lvls only(mz) */
  128.         
  129.         ReleaseResource(LCTable);
  130.         ReleaseResource(LInfo);
  131.  
  132.         levcount++;
  133.     }    while(thislev != 128 && levcount < MAXSELECTABLES && 
  134.             (levcount <= (int)(highestLastLevel/2) || PlayOptions->restart));
  135.     /* while cond will let player start up to highest odd level completed in last     */
  136.     /* game (mz) if in arcade mode (PlayOptions->restart==0), else                     */
  137.     /* PlayOptions->restart==1 so the cond will contribute a true to                 */
  138.     /* the while() test.                                                            */
  139.     
  140.     
  141.     return    levcount;
  142. }
  143.  
  144. int        DoLevelSelect(highestLastLevel)
  145. int *highestLastLevel;
  146. {
  147.                 selectable    stable[MAXSELECTABLES];
  148.     register    int            i,j;
  149.     register    int            x,y;
  150.                 static    int    thelevel=0;
  151.                 int            reallevel;
  152.                 int            theoffset=0;
  153.                 int            done=0;
  154.                 Point        mouse,CenterMouse;
  155.     register    int            direction;
  156.     register    ColorSpec    *colp;
  157.                 Handle        SelColors;
  158.                 int            OldFrameSpeed;
  159.                 int            levelnum;               /* temp holding variable (mz) */
  160.     
  161.     if (*highestLastLevel<9)
  162.         *highestLastLevel=9;
  163.         
  164.     SelColors=GetResource('CLOT',128);
  165.     HandToHand(&SelColors);
  166.     HLock(SelColors);
  167.     colp = (ColorSpec *)*SelColors;
  168.     
  169.     LastLevel=LastSelect=CreateStable(stable,*highestLastLevel)-1;
  170.     
  171.     CenterMouse.h=(VA.DisplayFrame.right+VA.DisplayFrame.left)/2;
  172.     CenterMouse.v=(VA.DisplayFrame.bottom+VA.DisplayFrame.top)/2;
  173.  
  174.     mouse=CenterMouse;
  175.     GetSetMouse(&mouse);
  176.  
  177.     VAEraseBuffer();
  178.     VACatchUp();
  179.     
  180.     BoxSize.h=VA.frame.right/5;
  181.     BoxSize.v=BoxSize.h;
  182.     
  183.     OldFrameSpeed = VA.FrameSpeed;
  184.     VA.FrameSpeed = 6;
  185.  
  186.     do
  187.     {    reallevel=thelevel+(theoffset>BoxSize.h/2 ? 1:0);
  188.         GameEvent();
  189.     
  190.         switch(Event.what)
  191.         {
  192.             case keyDown:
  193.             case autoKey:
  194.                 switch((char)Event.message)
  195.                 {    case 'p':
  196.                     case 'P':
  197.                         GamePause(LevelSelectRunning);
  198.                         break;
  199.                     case 'Q':
  200.                     case 'q':
  201.                     case 27:
  202.                     case 13:
  203.                         done=-1;
  204.                         break;
  205.                     default:
  206.                         PlayA(PhazerIn,0);
  207.                         PlayB(PhazerIn,0);
  208.                         done=stable[reallevel].leveltemplate;
  209.                         break;
  210.                 }
  211.                 break;
  212.             case mouseUp:
  213.                 PlayA(PhazerIn,0);
  214.                 PlayB(PhazerIn,0);
  215.                 done=stable[reallevel].leveltemplate;
  216.                 break;
  217.             case mouseDown:
  218.                 break;
  219.         }
  220.  
  221.         mouse=CenterMouse;
  222.         GetSetMouse(&mouse);
  223.         
  224.         if(mouse.h)
  225.         {    theoffset-=mouse.h;
  226.             direction=(direction/2)+mouse.h;
  227.             if(direction==0) direction=mouse.h;
  228.         }
  229.         else
  230.         {    if(theoffset!=0)
  231.             {    theoffset-=direction;
  232.                 if(theoffset<0)    theoffset=0;
  233.                 if(theoffset>BoxSize.h) theoffset=BoxSize.h;
  234.             }
  235.         }
  236.         while(theoffset<0)
  237.         {    theoffset+=BoxSize.h;
  238.              thelevel--; 
  239.             /* thelevel -= 2; */
  240.         }
  241.         if(thelevel<0)
  242.         {    thelevel=0;
  243.             theoffset=0;
  244.         }
  245.  
  246.         while(theoffset>=BoxSize.h)
  247.         {    theoffset-=BoxSize.h;
  248.              thelevel++; 
  249.         /*    thelevel += 2; */
  250.         }
  251.  
  252.         if(thelevel>=LastSelect)    
  253.         {    thelevel=LastSelect;
  254.             theoffset=0;
  255.         }
  256.  
  257.         for(i=0;i<6;i++)
  258.         {    int        lvnum = thelevel+i-2;
  259.         
  260.             if(lvnum>=0 && lvnum<=LastLevel)
  261.             {    VA.color=i+1;
  262.                 DrawLevelPresentation(i * BoxSize.h-theoffset,stable[lvnum].levelresource);
  263.                 colp[i+1]=stable[lvnum].levelcolor;
  264.             }
  265.         }
  266.  
  267.         VA.segmscale = BoxSize.v>>4;
  268.         if(VA.segmscale<1) VA.segmscale = 1;
  269.         VA.color = BG1;
  270.         /* print level number below box */
  271.         levelnum = thelevel+(theoffset>BoxSize.h/2 ? 1:0);
  272.         VADrawPadNumber(stable[levelnum].levelnumber
  273.                         ,2*BoxSize.h+BoxSize.h/2,VA.frame.bottom-4*VA.segmscale,3);
  274.     
  275.         /* show starting level bonus on top of box */
  276.         VADrawPadNumber(stable[levelnum].levelbonus,2*BoxSize.h+BoxSize.h/2 + 4*VA.segmscale,
  277.                         VA.frame.bottom-(BoxSize.v)*(1.6),7);
  278.         VA.color=0;
  279.         x = BoxSize.h * 2;
  280.         y = VA.frame.bottom - BoxSize.v / 2;
  281.  
  282.         VAMoveTo    (x,                y);
  283.         VASafeLineTo(x+BoxSize.h,    y);
  284.         VASafeLineTo(x+BoxSize.h,    y-BoxSize.h);
  285.         VASafeLineTo(x,                y-BoxSize.h);
  286.         VASafeLineTo(x,                y);
  287.     
  288.         VASetColors(SelColors);
  289.         VAStep();
  290.  
  291. #define    ADVERTISE
  292. #ifdef    ADVERTISE            
  293.         {    unsigned
  294.  
  295.             char    *funtext=(void *)"\p ARASHI *** Copyright 1991 Project STORM Team, All Rights Reserved *** Version 1.1 *** Please select your starting level ***";
  296.             int        rotme=(VA.FrameCounter) % *funtext;
  297.             
  298.             VA.segmscale= VA.segmscale/3;
  299.             if(VA.segmscale<=1) VA.segmscale=2;
  300.             VA.color=BG2;
  301.             VAMoveTo(12,VA.frame.bottom-BoxSize.v*5/3 - 100);  /* moved up for lvBonus(mz) */
  302.             VADrawText((char *)funtext,1+rotme,*funtext-rotme);
  303.             VADrawText((char *)funtext,1,rotme);
  304.         }
  305. #endif
  306.     }    while(!done);
  307.     
  308.     VAEraseBuffer();
  309.     VACatchUp();
  310.  
  311.     HUnlock(SelColors);    
  312.     DisposHandle(SelColors);
  313.  
  314.     VA.FrameSpeed = OldFrameSpeed;    
  315.     
  316.     return done;
  317. }
  318.